package org.footito.android.ui.activity;

import org.footito.android.R;
import org.footito.android.data.Status;
import org.footito.android.tools.ConvertingTools;
import org.footito.android.ui.adapters.CommentsBaseAdapter;

import android.os.Bundle;
import android.text.Html;
import android.text.method.LinkMovementMethod;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.ListView;
import android.widget.TextView;

import com.actionbarsherlock.app.SherlockFragment;

public class StatusInfoFragment extends SherlockFragment {
	private static final String STATUS_ID = "statusid";
	private Status mStatus;

	private TextView eventcontentTV;
	private TextView teamName;
	private ImageView teamFlag;
	private TextView timestamp;
	private TextView permanentLink;
	private ListView mListView;

	@Override
	public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
		View view = inflater.inflate(R.layout.event_info_fragment, null);
		mListView = (ListView) view.findViewById(R.id.list);

		// setContentView(R.layout.activity_event_info);
		View header = inflater.inflate(R.layout.event_info_list_header, null);
		getListView().addHeaderView(header);

		eventcontentTV = (TextView) header.findViewById(R.id.eventText);
		teamFlag = (ImageView) header.findViewById(R.id.blason);
		teamName = (TextView) header.findViewById(R.id.teamName);
		timestamp = (TextView) header.findViewById(R.id.TV_date);
		permanentLink = (TextView) header.findViewById(R.id.tv_permanentLink);

		permanentLink.setMovementMethod(LinkMovementMethod.getInstance());

		return view;
	}

	private ListView getListView() {
		return mListView;
	}

	@Override
	public void onResume() {
		super.onResume();

	}

	@Override
	public void onPause() {
		super.onPause();
	}

	public void setStatus(Status status) {
		this.mStatus = status;
		teamFlag.setImageBitmap(mStatus.getTeam().getPicture(getActivity()));
		teamName.setText(mStatus.getTeam().getName());
		timestamp.setText(ConvertingTools.getFormattedDate(mStatus.getTimestamp()));

		eventcontentTV.setText(mStatus.getContent());

		permanentLink.setText(Html.fromHtml("<a href=\"" + mStatus.getLink() + "\">Lien permanent</a>"));
		// <a href="http://www.footito.fr/event/35130">Lien permanent</a>

		getListView().setAdapter(new CommentsBaseAdapter(getActivity(), mStatus.getComments()));
		
	}
}
